import { Component } from '@angular/core';

import { NavController, ViewController} from 'ionic-angular';

import { Storage } from '@ionic/storage';

import { Common } from "../../../providers/common";

import _ from "lodash";
import {DraftDetailService} from "./detail.service";
import {FieldColumnModel} from "./field.column.model";
import {CoinService} from "./coin.service";

@Component({
	selector: 'modal-ipm-coin-column',
	templateUrl: 'column.modal.html',
  providers: [CoinService]
})
export class IpmColumnModal{
	moa_page_name: any = "modal-ipm-coin-column";
  moa_page_explain: any = "货币基金试算 - 自定义列";

  dataList = [];

  fieldColumnModel = new FieldColumnModel();

  resultType = "";

  title = "";

	constructor(
		public navCtrl: NavController,
    public common: Common,
    public viewCtrl: ViewController,
    public storage: Storage,
    public coinService: CoinService
	) {
	  this.resultType = this.viewCtrl.getNavParams().get("resultType");
	  this.title = this.fieldColumnModel.entity[this.resultType].name;
	  this.coinService.getCoinColumns().subscribe(columns => {
	    this.fieldColumnModel.entity = columns;
      this.storage.get("CustomFieldColumns").then(CustomFieldColumns => {
        this.dataList = this.fieldColumnModel.entity[this.resultType].fieldColumns;
        if (CustomFieldColumns) {
          _.forEach(this.dataList, data => {
            let temp = _.find(CustomFieldColumns[this.resultType], {fieldName: data.fieldName});
            if (temp) {
              data.isShow = temp["isShow"];
            }
          });
        }
      });
    });
  }

  ionViewDidEnter() {

  }

  closeModal() {
    this.viewCtrl.dismiss("close");
  }

  completeModal() {
	  this.viewCtrl.dismiss(this.dataList);
  }


}

